package com.ruoyi.web.controller.assets;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BorrowLog;
import com.ruoyi.system.service.IBrAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 借还日志Controller
 * 
 * @author hzl
 * @date 2025-02-09
 */
@RestController
@RequestMapping("/assets/brAudit")
public class BrAuditController extends BaseController
{
    @Autowired
    private IBrAuditService brAuditService;

    /**
     * 查询借还日志列表
     */
    @PreAuthorize("@ss.hasPermi('assets:brAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(BorrowLog borrowLog)
    {
        startPage();
        List<BorrowLog> list = brAuditService.selectBorrowLogList(borrowLog);
        return getDataTable(list);
    }

    /**
     * 导出借还日志列表
     */
    @PreAuthorize("@ss.hasPermi('assets:brAudit:export')")
    @Log(title = "借还日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BorrowLog borrowLog)
    {
        List<BorrowLog> list = brAuditService.selectBorrowLogList(borrowLog);
        ExcelUtil<BorrowLog> util = new ExcelUtil<BorrowLog>(BorrowLog.class);
        util.exportExcel(response, list, "借还日志数据");
    }

    /**
     * 获取借还日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:brAudit:query')")
    @GetMapping(value = "/{borrowLogId}")
    public AjaxResult getInfo(@PathVariable("borrowLogId") Long borrowLogId)
    {
        return success(brAuditService.selectBorrowLogByBorrowLogId(borrowLogId));
    }

    /**
     * 新增借还日志
     */
    @PreAuthorize("@ss.hasPermi('assets:brAudit:add')")
    @Log(title = "借还日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BorrowLog borrowLog)
    {
        return toAjax(brAuditService.insertBorrowLog(borrowLog));
    }

    /**
     * 修改借还日志
     */
    @PreAuthorize("@ss.hasPermi('assets:brAudit:edit')")
    @Log(title = "借还日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BorrowLog borrowLog)
    {
        return toAjax(brAuditService.updateBorrowLog(borrowLog));
    }

    /**
     * 删除借还日志
     */
    @PreAuthorize("@ss.hasPermi('assets:brAudit:remove')")
    @Log(title = "借还日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{borrowLogIds}")
    public AjaxResult remove(@PathVariable Long[] borrowLogIds)
    {
        return toAjax(brAuditService.deleteBorrowLogByBorrowLogIds(borrowLogIds));
    }
}
